<template>
  <div class="mine-page">
    <!-- 顶部栏 -->
    <div class="header">
      <el-icon class="back-icon"><ArrowLeft /></el-icon>
      <span class="title">我的</span>
      <el-icon class="more-icon"><MoreFilled /></el-icon>
    </div>

    <!-- 用户信息卡片 -->
    <el-card class="user-info-card">
      <div class="user-info-main">
        <img class="avatar" :src="user.avatar" alt="头像" />
        <div class="user-meta">
          <div class="nickname">
            {{ user.nickname }}
            <el-tag size="small" type="info">AI语音实名认证</el-tag>
          </div>
          <div class="phone">{{ user.phone }}</div>
        </div>
        <el-button class="charge-btn" type="primary" size="small">充值</el-button>
      </div>
      <div class="user-stats">
        <div class="stat">
          <div class="stat-value">{{ user.power }}</div>
          <div class="stat-label">算力</div>
        </div>
        <div class="stat">
          <div class="stat-value">{{ user.voiceCount }}</div>
          <div class="stat-label">音色</div>
        </div>
      </div>
    </el-card>

    <!-- 功能按钮区 -->
    <div class="feature-buttons">
      <el-button class="feature-btn" plain>我要兑换</el-button>
      <el-button class="feature-btn" plain>算力记录</el-button>
    </div>

    <!-- 分类Tab -->
    <div class="tabs">
      <el-radio-group v-model="tab" size="small">
        <el-radio-button label="视频" />
        <el-radio-button label="音频" />
        <el-radio-button label="音色" />
      </el-radio-group>
    </div>

    <!-- Tab内容区 -->
    <div v-if="tab === '视频'">
      <!-- 视频列表渲染 -->
      <el-card v-for="item in voices" :key="item.id" class="voice-item">
        <div class="voice-item-header">
          <div class="voice-title">
            <el-icon><Headset /></el-icon>
            <span>{{ item.name }}</span>
            <el-tag v-if="item.status === '修改中'" size="mini" type="warning">修改中</el-tag>
          </div>
          <div class="voice-audio">
            <el-icon><VideoPlay /></el-icon>
          </div>
        </div>
        <div class="voice-meta">
          <span>创建时间：{{ item.time }}</span>
        </div>
        <div class="voice-actions">
          <span>免费修改次数：<span :class="{'danger': item.freeEdit === 0}">{{ item.freeEdit }}次</span></span>
          <el-button size="small" type="info" plain>查看记录</el-button>
          <el-button size="small" type="danger" plain>修改音色</el-button>
        </div>
      </el-card>
      <el-button class="create-btn" type="primary" round>创作视频</el-button>
    </div>
    <div v-else-if="tab === '音频'">
      <!-- 音频列表渲染 -->
      <el-card v-for="item in voices" :key="item.id" class="voice-item">
        <div class="voice-item-header">
          <div class="voice-title">
            <el-icon><Headset /></el-icon>
            <span>{{ item.name }}</span>
            <el-tag v-if="item.status === '修改中'" size="mini" type="warning">修改中</el-tag>
          </div>
          <div class="voice-audio">
            <el-icon><VideoPlay /></el-icon>
          </div>
        </div>
        <div class="voice-meta">
          <span>创建时间：{{ item.time }}</span>
        </div>
        <div class="voice-actions">
          <span>免费修改次数：<span :class="{'danger': item.freeEdit === 0}">{{ item.freeEdit }}次</span></span>
          <el-button size="small" type="info" plain>查看记录</el-button>
          <el-button size="small" type="danger" plain>修改音色</el-button>
        </div>
      </el-card>
      <el-button class="create-btn" type="primary" round>创作音频</el-button>
    </div>
    <div v-else>
      <!-- 音色列表渲染 -->
      <el-card v-for="item in voices" :key="item.id" class="voice-item">
        <div class="voice-item-header">
          <div class="voice-title">
            <el-icon><Headset /></el-icon>
            <span>{{ item.name }}</span>
            <el-tag v-if="item.status === '修改中'" size="mini" type="warning">修改中</el-tag>
          </div>
          <div class="voice-audio">
            <el-icon><VideoPlay /></el-icon>
          </div>
        </div>
        <div class="voice-meta">
          <span>创建时间：{{ item.time }}</span>
        </div>
        <div class="voice-actions">
          <span>免费修改次数：<span :class="{'danger': item.freeEdit === 0}">{{ item.freeEdit }}次</span></span>
          <el-button size="small" type="info" plain>查看记录</el-button>
          <el-button size="small" type="danger" plain>修改音色</el-button>
        </div>
      </el-card>
      <el-button class="create-btn" type="primary" round>创作音色</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ArrowLeft, MoreFilled, CirclePlusFilled, Headset, VideoPlay } from '@element-plus/icons-vue'

/**
 * 当前Tab
 * @type {import('vue').Ref<string>}
 */
const tab = ref('视频')

/**
 * 用户信息
 * @typedef {Object} User
 * @property {string} avatar 头像URL
 * @property {string} nickname 昵称
 * @property {string} phone 手机号
 * @property {number} power 算力
 * @property {number} voiceCount 音色数量
 */
/**
 * @type {User}
 */
const user = {
  avatar: 'https://img1.baidu.com/it/u=123456789,987654321&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200',
  nickname: '张三的昵称很长非常长的昵称',
  phone: '18812341234',
  power: 18000,
  voiceCount: 1
}

/**
 * 音色列表项
 * @typedef {Object} VoiceItem
 * @property {string} id 唯一ID
 * @property {string} name 音色名称
 * @property {string} time 创建时间
 * @property {number} freeEdit 免费修改次数
 * @property {string} status 状态
 */
/**
 * @type {VoiceItem[]}
 */
const voices = [
  {
    id: '1',
    name: '周导-音色',
    time: '2024-09-20 14:00:23',
    freeEdit: 4,
    status: ''
  },
  {
    id: '2',
    name: '周导-音色',
    time: '2024-09-20 14:00:23',
    freeEdit: 0,
    status: '修改中'
  }
]
</script>

<style scoped>
.mine-page {
  background: #f6f7fb;
  min-height: 100vh;
  padding-bottom: 20px;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 8px 12px;
  background: #fff;
  font-size: 18px;
  font-weight: bold;
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-icon, .more-icon {
  font-size: 22px;
  color: #333;
  cursor: pointer;
}
.title {
  flex: 1;
  text-align: center;
  color: #222;
}
.user-info-card {
  margin: 12px 12px 0 12px;
  border-radius: 14px;
  background: linear-gradient(90deg, #2566e8 0%, #1e3c72 100%);
  color: #fff;
  box-shadow: 0 2px 8px #e3e8f7;
}
.user-info-main {
  display: flex;
  align-items: center;
  padding-bottom: 8px;
}
.avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  margin-right: 12px;
  border: 2px solid #fff;
}
.user-meta {
  flex: 1;
}
.nickname {
  font-size: 16px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.phone {
  font-size: 13px;
  opacity: 0.85;
}
.charge-btn {
  background: #fff;
  color: #2566e8;
  border-radius: 16px;
  font-weight: bold;
  margin-left: 8px;
}
.user-stats {
  display: flex;
  justify-content: space-around;
  border-top: 1px solid rgba(255,255,255,0.2);
  padding-top: 8px;
}
.stat {
  text-align: center;
}
.stat-value {
  font-size: 20px;
  font-weight: bold;
}
.stat-label {
  font-size: 13px;
  opacity: 0.9;
}
.feature-buttons {
  display: flex;
  gap: 12px;
  margin: 16px 12px 0 12px;
}
.feature-btn {
  flex: 1;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  background: #fff;
  color: #2566e8;
  border: 1px solid #2566e8;
}
.tabs {
  margin: 18px 12px 0 12px;
  background: #fff;
  border-radius: 10px;
  padding: 8px 0 2px 8px;
}
.add-voice-card {
  margin: 16px 12px 0 12px;
  border-radius: 12px;
  background: #f4faff;
  text-align: center;
  color: #2566e8;
  box-shadow: 0 2px 8px #e3e8f7;
}
.add-voice-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0 8px 0;
}
.add-icon {
  font-size: 38px;
  margin-bottom: 6px;
}
.add-voice-text {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 4px;
}
.add-voice-desc {
  font-size: 12px;
  color: #2566e8;
  opacity: 0.7;
}
.voice-list {
  margin: 16px 12px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.voice-item {
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 8px #e3e8f7;
  padding: 12px 14px 10px 14px;
}
.voice-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.voice-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 500;
}
.voice-audio {
  color: #2566e8;
  font-size: 20px;
  cursor: pointer;
}
.voice-meta {
  font-size: 12px;
  color: #888;
  margin: 4px 0 6px 0;
}
.voice-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.danger {
  color: #f56c6c;
  font-weight: bold;
}
/* 底部创作按钮居中样式 */
.create-btn {
  display: block;
  margin: 24px auto 0 auto;
  width: 90%;
  max-width: 340px;
  font-size: 18px;
  font-weight: bold;
  border-radius: 24px;
  box-shadow: 0 2px 8px #e3e8f7;
}
</style>
